package com.ww.java.box;

/**
 * 自动拆箱、装箱性能测试
 */
public class BoxDemo {

    public static void main(String[] args) {
        test01();
        test02();
    }

    /**
     * 自动装箱
     * 自动装箱耗时：168ms
     */
    static void test01() {
        long beginTime = System.currentTimeMillis();
        Integer result = 0;
        for (int i = 0; i < 50000000; i++) {
            result += i;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("自动装箱耗时：" + (endTime - beginTime) + "ms");
    }

    /**
     * 自动装箱耗时：14ms
     */
    static void test02() {
        long beginTime = System.currentTimeMillis();
        int result = 0;
        for (int i = 0; i < 50000000; i++) {
            result += i;
        }
        long endTime = System.currentTimeMillis();
        System.out.println("自动装箱耗时：" + (endTime - beginTime) + "ms");
    }
}
